﻿using Coldairarrow.Business.PB;
using Coldairarrow.Entity.Base;
using Coldairarrow.Entity.DTO;
using Coldairarrow.Entity.PB;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.PB
{
    [Route("/PB/[controller]/[action]")]
    public class PB_RepairOrderApplyController : BaseApiController
    {
        #region DI

        public PB_RepairOrderApplyController(IPB_RepairOrderApplyBusiness pB_RepairOrderApplyBus)
        {
            _pB_RepairOrderApplyBus = pB_RepairOrderApplyBus;
        }

        IPB_RepairOrderApplyBusiness _pB_RepairOrderApplyBus { get; }

        #endregion

        #region 获取

        [HttpPost]
        public async Task<PageResult<Base_RepairOrderApply>> GetDataList(PageInput<ConditionDTO> input)
        {
            return await _pB_RepairOrderApplyBus.GetDataListAsync(input);
        }

        [HttpPost]
        public async Task<Base_RepairOrderApply> GetTheData(IdInputDTO input)
        {
            return await _pB_RepairOrderApplyBus.GetTheDataAsync(input.id);
        }

        #endregion

        #region 提交

        [HttpPost]
        public async Task SaveData(Base_RepairOrderApply data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);

                await _pB_RepairOrderApplyBus.AddDataAsync(data);
            }
            else
            {
                await _pB_RepairOrderApplyBus.UpdateDataAsync(data);
            }
        }

        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _pB_RepairOrderApplyBus.DeleteDataAsync(ids);
        }


        /// <summary>
        /// pc 获取维修申请列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PageResult<Base_RepairOrderApplyDTO>> GetRepairOrderApplyList(PageInput<PB_ScheduleDetailConditionDTO> input) {

            var listData = await _pB_RepairOrderApplyBus.GetRepairOrderApplyList(input);
            return listData;
        }
        /// <summary>
        /// 根据维修申请获取维修工单及明细数据
        /// </summary>
        /// <param name="ApplyId"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Base_RepairOrderApplyListInfo> GetRepairOrderApplyListInfo(string ApplyId)
        {
            var listData = await _pB_RepairOrderApplyBus.GetRepairOrderApplyListInfo(ApplyId);
            return listData;
        }

        /// <summary>
        /// 获取维修工单明细数据
        /// </summary>
        /// <param name="ApplyId"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Base_RepairOrderList> GetRepairOrderList(string ApplyId) {
            var SS = await _pB_RepairOrderApplyBus.GetRepairOrderList(ApplyId);
            return SS;
        }

        /// <summary>
        /// 打印维修工单数据
        /// </summary>
        /// <param name="ApplyId"></param>
        /// <returns></returns>
        [HttpPost]
        public   async Task<Base_RepairOrderPrint> Base_RepairOrderPrint(string ApplyId) {
            var listData = await _pB_RepairOrderApplyBus.Base_RepairOrderPrint(ApplyId);
            return listData;
        }

        /// <summary>
        /// 审核维修申请单 创建维修领药单
        /// </summary>
        /// <param name="ApplyId"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task ToExamineRepairOrderApply(string ApplyId) {
             await _pB_RepairOrderApplyBus.ToExamineRepairOrderApply(ApplyId);
        }
        /// <summary>
        /// 获取维修类型
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [NoCheckJWT]
        public  async Task<List<Base_EnumItem>> RepairOrderApplyType() {
            return await _pB_RepairOrderApplyBus.RepairOrderApplyType();
        }

        /// <summary>
        /// 通过设备过去维修记录
        /// </summary>
        /// <param name="input"></param>
        /// <param name="DeviceId"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PageResult<Base_RepairOrderApplyDTO>> GetRepairOrderDeviceId(PageInput<ConditionDTO> input, string DeviceId) {

            var listData = await _pB_RepairOrderApplyBus.GetRepairOrderDeviceId(input,DeviceId);
            return listData;
        }

        /// <summary>
        /// PC创建设备维修工单数据
        /// </summary>
        /// <param name="data">数据</param>
        /// <returns></returns>
        [HttpPost]
        public async Task EquipmentPatrolAdd(Base_RepairOrderMainAdd data) {
            await _pB_RepairOrderApplyBus.EquipmentPatrolAdd(data);
        }
        #endregion
    }
}